package com.yzh.dxpro.p3.sta;
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import com.yzh.dxpro.p4.utils.TProperties;

public class DxStaTwoReducer extends Reducer<Text,Text,NullWritable,Text>{
	protected void reduce(Text key, Iterable<Text> values, 
			Reducer<Text, Text, NullWritable, Text>.Context context)
			throws IOException, InterruptedException {
		int uvsum=0,pvsum=0;
		//values[i] : [ user id | sum]
		Iterator<Text> it = values.iterator();
		while(it.hasNext()) {
			Text value = it.next();
			String temp[] = value.toString().split(TProperties.getValue("fileoutsplit"));
			pvsum=pvsum+Integer.parseInt(temp[1]);
			uvsum++;
		}
		//str =       key                           |                     uv            |                         pvsum
		String str  = key.toString()+TProperties.getValue("outfilesplit")+uvsum+TProperties.getValue("outfilesplit")+pvsum;
		Text ovalue = new Text(str); 
		context.write(NullWritable.get(), ovalue);
		System.out.println("~~~~reducer2");
	}

}
